﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace HRMService
{
    // NOTE: If you change the class name "Salary" here, you must also update the reference to "Salary" in App.config.

    public partial class MainService : ISalary
    {
        public DataSet Salary_TongHopMau02(int period, int month, int year, int BranchID)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_TongHopMau02", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            dbCmd.Parameters.AddWithValue("@period", period);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_TongHopMau03(int period, int month, int year, int BranchID)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_TongHopMau03", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            dbCmd.Parameters.AddWithValue("@period", period);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public DataSet Salary_GetSalaryFund(int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_GetSalaryFund", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public DataSet Salary_GetForServiceCharge(DateTime date, int DepartmentID)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_GetForServiceCharge", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Date", date);
            dbCmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public DataSet Salary_GetEmployeeSalary(int EmployeeID, int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_GetSalaryWithEmployee", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@EmployeeID", EmployeeID);
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_GetLastMonth(int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_GetLastMonth", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_CountEmployee(int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_CountEmployee", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_GetList(out int itemCount, int currPage, int pageSize, int BranchID, int DepartmentID, int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_GetList", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@CurrentPage", currPage);
            dbCmd.Parameters.AddWithValue("@PageSize", pageSize);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            dbCmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
                itemCount = Convert.ToInt32(retVal.Tables[1].Rows[0][0]);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_Report(int BranchID, int DepartmentID, int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_Report", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            dbCmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public DataSet Salary_PaySlip(int DepartmentID, int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_PaySlip", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public DataSet Salary_PayrollDetailReport(int DepartmentID, int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_PayrollDetailReport", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public DataSet Salary_PayrollDetailReportSendToBank(int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_PayrollDetailReportSendToBank", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public DataSet Salary_PayrollDetailReportAll(int month, int year)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_PayrollDetailReportAll", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public SalaryInfo Salary_GetInfo(int SalaryID)
        {
            SalaryInfo retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_GetInfo", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@SalaryID", SalaryID);
            SqlDataReader dr = null;
            try
            {
                dbConn.Open();
                dr = dbCmd.ExecuteReader();
                if (dr.Read())
                {
                    retVal = new SalaryInfo();
                    retVal.ID = Convert.ToInt32(dr["Salary_ID"]);
                    retVal.EmployeeID = Convert.ToInt32(dr["Salary_EmployeeID"]);
                    retVal.BasicSalary = Convert.ToDecimal(dr["Salary_Basic"]);
                    retVal.BasicFactor = Convert.ToDecimal(dr["Salary_BasicFactor"]);
                    retVal.PositionFactor = Convert.ToDecimal(dr["Salary_PositionFactor"]);
                    retVal.SeniorityFactor = Convert.ToDecimal(dr["Salary_SeniorityFactor"]);
                    retVal.PositionAllowance = Convert.ToDecimal(dr["Salary_Position"]);
                    retVal.SeniorityAllowance = Convert.ToDecimal(dr["Salary_Seniority"]);
                    retVal.OverSeniorityAllowance = Convert.ToDecimal(dr["Salary_OverSeniority"]);
                    retVal.CompanySalary = Convert.ToDecimal(dr["Salary_Company"]);
                    retVal.CompanyFactor = Convert.ToDecimal(dr["Salary_CompanyFactor"]);
                    retVal.ResponseSalary = Convert.ToDecimal(dr["Salary_Response"]);
                    retVal.ResponseFactor = Convert.ToDecimal(dr["Salary_ResponseFactor"]);
                    retVal.TotalDateWork = Convert.ToDecimal(dr["Salary_TotalDateWork"]);
                    retVal.TotalDateOutWork = Convert.ToDecimal(dr["Salary_TotalDateOutWork"]);
                    retVal.TotalLeavePaid = Convert.ToDecimal(dr["Salary_TotalLeavePaid"]);
                    retVal.TotalLeaveUnPaid = Convert.ToDecimal(dr["Salary_TotalLeaveUnPaid"]);
                    retVal.TradeUnion = Convert.ToDecimal(dr["Salary_TradeUnion"]);
                    retVal.IncomeTax = Convert.ToDecimal(dr["Salary_IncomeTax"]);
                    retVal.OtherResponse = Convert.ToDecimal(dr["Salary_OtherResponse"]);
                    retVal.OtherDeduction = Convert.ToDecimal(dr["Salary_OtherDeduction"]);
                    retVal.CompanyLunch = Convert.ToDecimal(dr["Salary_Lunch"]);
                    retVal.TelephoneCost = Convert.ToDecimal(dr["Salary_TelephoneCost"]);
                    retVal.OverTime = Convert.ToDecimal(dr["Salary_OverTime"]);
                    retVal.Date = Convert.ToDateTime(dr["Salary_Date"]);
                    retVal.ProbationFactor = Convert.ToDecimal(dr["Salary_ProbationFactor"]);
                    retVal.EmployeeSocialInc = Convert.ToDecimal(dr["Salary_EmployeeSocialIns"]);
                    retVal.EmployeeMedicalInc = Convert.ToDecimal(dr["Salary_EmployeeMedicalIns"]);
                    retVal.SocialInc = Convert.ToDecimal(dr["Salary_SocialIns"]);
                    retVal.MedicalInc = Convert.ToDecimal(dr["Salary_MedicalIns"]);
                    retVal.OverSeniorityFactor = Convert.ToDecimal(dr["Salary_OverSeniorityFactor"]);
                    retVal.Award = Convert.ToDecimal(dr["Salary_Award"]);
                    retVal.LaterSalary = Convert.ToDecimal(dr["Salary_LaterSalary"]);
                    retVal.Advance = Convert.ToDecimal(dr["Salary_Advance"]);
                    retVal.UnemployedIns = Convert.ToDecimal(dr["Salary_UnemployedIns"]);
                    retVal.UnemployedInsCompany = Convert.ToDecimal(dr["Salary_UnemployedInsCompany"]);
                }
            }
            finally
            {
                if (dr != null) dr.Close();
                dbConn.Close();
            }
            return retVal;
        }

        public SalaryInfo Salary_TotalByQuarter(int _month, int _Year, int BranchID)
        {
            SalaryInfo retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_TotalByQuarter", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", _month);
            dbCmd.Parameters.AddWithValue("@Year", _Year);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            SqlDataReader dr = null;
            try
            {
                dbConn.Open();
                dr = dbCmd.ExecuteReader();
                if (dr.Read())
                {
                    retVal = new SalaryInfo();
                    if (dr["Salary_Basic"] != DBNull.Value)
                        retVal.BasicSalary = Convert.ToDecimal(dr["Salary_Basic"]);

                }
            }
            finally
            {
                if (dr != null) dr.Close();
                dbConn.Close();
            }
            return retVal;
        }

        public bool Salary_CheckExistEmployee(int EmployeeID, int month, int year)
        {
            bool retVal = false;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_GetEmployee", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Salary_EmployeeID", EmployeeID);
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            try
            {
                dbConn.Open();
                int Count = Convert.ToInt32(dbCmd.ExecuteScalar());
                retVal = Count > 0 ? true : false;
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public int Salary_Insert(SalaryInfo eInfo)
        {
            int retVal = 0;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_Insert", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Salary_EmployeeID", eInfo.EmployeeID);
            dbCmd.Parameters.AddWithValue("@Salary_Date", eInfo.Date);
            dbCmd.Parameters.AddWithValue("@Salary_BasicFactor", eInfo.BasicFactor);
            dbCmd.Parameters.AddWithValue("@Salary_PositionFactor", eInfo.PositionFactor);
            dbCmd.Parameters.AddWithValue("@Salary_SeniorityFactor", eInfo.SeniorityFactor);
            dbCmd.Parameters.AddWithValue("@Salary_Basic", eInfo.BasicSalary);
            dbCmd.Parameters.AddWithValue("@Salary_Position", eInfo.PositionAllowance);
            dbCmd.Parameters.AddWithValue("@Salary_Seniority", eInfo.SeniorityAllowance);
            dbCmd.Parameters.AddWithValue("@Salary_OverSeniority", eInfo.OverSeniorityAllowance);
            dbCmd.Parameters.AddWithValue("@Salary_CompanyFactor", eInfo.CompanyFactor);
            dbCmd.Parameters.AddWithValue("@Salary_Company", eInfo.CompanySalary);
            dbCmd.Parameters.AddWithValue("@Salary_ResponseFactor", eInfo.ResponseFactor);
            dbCmd.Parameters.AddWithValue("@Salary_Response", eInfo.ResponseSalary);
            dbCmd.Parameters.AddWithValue("@Salary_TotalDateWork", eInfo.TotalDateWork);
            dbCmd.Parameters.AddWithValue("@Salary_ToTalDateOutWork", eInfo.TotalDateOutWork);
            dbCmd.Parameters.AddWithValue("@Salary_TotalLeavePaid", eInfo.TotalLeavePaid);
            dbCmd.Parameters.AddWithValue("@Salary_TotalLeaveUnPaid", eInfo.TotalLeaveUnPaid);
            dbCmd.Parameters.AddWithValue("@Salary_OverTime", eInfo.OverTime);
            dbCmd.Parameters.AddWithValue("@Salary_ProbationFactor", eInfo.ProbationFactor);
            dbCmd.Parameters.AddWithValue("@Salary_TradeUnion", eInfo.TradeUnion);
            dbCmd.Parameters.AddWithValue("@Salary_IncomeTax", eInfo.IncomeTax);
            dbCmd.Parameters.AddWithValue("@Salary_Lunch", eInfo.CompanyLunch);
            dbCmd.Parameters.AddWithValue("@Salary_TelephoneCost", eInfo.TelephoneCost);
            dbCmd.Parameters.AddWithValue("@Salary_OtherResponse", eInfo.OtherResponse);
            dbCmd.Parameters.AddWithValue("@Salary_OtherDeduction", eInfo.OtherDeduction);
            dbCmd.Parameters.AddWithValue("@Salary_EmployeeSocialIns", eInfo.EmployeeSocialInc);
            dbCmd.Parameters.AddWithValue("@Salary_EmployeeMedicalIns", eInfo.EmployeeMedicalInc);
            dbCmd.Parameters.AddWithValue("@Salary_SocialIns", eInfo.SocialInc);
            dbCmd.Parameters.AddWithValue("@Salary_MedicalIns", eInfo.MedicalInc);
            dbCmd.Parameters.AddWithValue("@Salary_OverSeniorityFactor", eInfo.OverSeniorityFactor);
            dbCmd.Parameters.AddWithValue("@Salary_LaterSalary", eInfo.LaterSalary);
            dbCmd.Parameters.AddWithValue("@Salary_Award", eInfo.Award);
            dbCmd.Parameters.AddWithValue("@Salary_Advance", eInfo.Advance);
            dbCmd.Parameters.AddWithValue("@Salary_UnemployedIns", eInfo.UnemployedIns);
            dbCmd.Parameters.AddWithValue("@Salary_UnemployedInsCompany", eInfo.UnemployedInsCompany);
            try
            {
                dbConn.Open();
                retVal = Convert.ToInt32(dbCmd.ExecuteScalar());
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public bool Salary_Update(SalaryInfo eInfo)
        {
            bool retVal = false;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_Update", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Salary_EmployeeID", eInfo.EmployeeID);
            dbCmd.Parameters.AddWithValue("@Salary_Date", eInfo.Date);
            dbCmd.Parameters.AddWithValue("@Salary_BasicFactor", eInfo.BasicFactor);
            dbCmd.Parameters.AddWithValue("@Salary_PositionFactor", eInfo.PositionFactor);
            dbCmd.Parameters.AddWithValue("@Salary_SeniorityFactor", eInfo.SeniorityFactor);
            dbCmd.Parameters.AddWithValue("@Salary_Basic", eInfo.BasicSalary);
            dbCmd.Parameters.AddWithValue("@Salary_Position", eInfo.PositionAllowance);
            dbCmd.Parameters.AddWithValue("@Salary_Seniority", eInfo.SeniorityAllowance);
            dbCmd.Parameters.AddWithValue("@Salary_OverSeniority", eInfo.OverSeniorityAllowance);
            dbCmd.Parameters.AddWithValue("@Salary_CompanyFactor", eInfo.CompanyFactor);
            dbCmd.Parameters.AddWithValue("@Salary_Company", eInfo.CompanySalary);
            dbCmd.Parameters.AddWithValue("@Salary_ResponseFactor", eInfo.ResponseFactor);
            dbCmd.Parameters.AddWithValue("@Salary_Response", eInfo.ResponseSalary);
            dbCmd.Parameters.AddWithValue("@Salary_TotalDateWork", eInfo.TotalDateWork);
            dbCmd.Parameters.AddWithValue("@Salary_ToTalDateOutWork", eInfo.TotalDateOutWork);
            dbCmd.Parameters.AddWithValue("@Salary_TotalLeavePaid", eInfo.TotalLeavePaid);
            dbCmd.Parameters.AddWithValue("@Salary_TotalLeaveUnPaid", eInfo.TotalLeaveUnPaid);
            dbCmd.Parameters.AddWithValue("@Salary_OverTime", eInfo.OverTime);
            dbCmd.Parameters.AddWithValue("@Salary_ProbationFactor", eInfo.ProbationFactor);
            dbCmd.Parameters.AddWithValue("@Salary_TradeUnion", eInfo.TradeUnion);
            dbCmd.Parameters.AddWithValue("@Salary_IncomeTax", eInfo.IncomeTax);
            dbCmd.Parameters.AddWithValue("@Salary_Lunch", eInfo.CompanyLunch);
            dbCmd.Parameters.AddWithValue("@Salary_TelephoneCost", eInfo.TelephoneCost);
            dbCmd.Parameters.AddWithValue("@Salary_OtherResponse", eInfo.OtherResponse);
            dbCmd.Parameters.AddWithValue("@Salary_OtherDeduction", eInfo.OtherDeduction);
            dbCmd.Parameters.AddWithValue("@Salary_EmployeeSocialIns", eInfo.EmployeeSocialInc);
            dbCmd.Parameters.AddWithValue("@Salary_EmployeeMedicalIns", eInfo.EmployeeMedicalInc);
            dbCmd.Parameters.AddWithValue("@Salary_SocialIns", eInfo.SocialInc);
            dbCmd.Parameters.AddWithValue("@Salary_MedicalIns", eInfo.MedicalInc);
            dbCmd.Parameters.AddWithValue("@Salary_OverSeniorityFactor", eInfo.OverSeniorityFactor);
            dbCmd.Parameters.AddWithValue("@Salary_LaterSalary", eInfo.LaterSalary);
            dbCmd.Parameters.AddWithValue("@Salary_Award", eInfo.Award);
            dbCmd.Parameters.AddWithValue("@Salary_Advance", eInfo.Advance);
            dbCmd.Parameters.AddWithValue("@Salary_UnemployedIns", eInfo.UnemployedIns);
            dbCmd.Parameters.AddWithValue("@Salary_UnemployedInsCompany", eInfo.UnemployedInsCompany);
            try
            {
                dbConn.Open();
                if (dbCmd.ExecuteNonQuery() > 0)
                {
                    retVal = true;
                }
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_Mau03TangMoi(int month, int year, int BranchID)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_BaoHiem_Form03_TangMoi", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_Mau03Giam(int month, int year, int BranchID)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_BaoHiem_Form03_Giam", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_Mau03DCLuong(int month, int year, int BranchID)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_BaoHiem_Form03_DCLuong", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public DataSet Salary_Mau03BoSungBHTN(int month, int year, int BranchID)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_BaoHiem_Form03_BoSungBHTN", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public DataSet Salary_Mau03CuoiKy(int month, int year, int BranchID)
        {
            DataSet retVal = null;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_BaoHiem_GetForForm03_TongHopCuoiKy", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);
            dbCmd.Parameters.AddWithValue("@BranchID", BranchID);
            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public bool Salary_Calculate(int month, int year)
        {
            bool retVal = false;
            SqlConnection dbConn = new SqlConnection(Properties.Settings.Default.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("HRM_Salary_Calculate", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@month", month);
            dbCmd.Parameters.AddWithValue("@year", year);

            try
            {
                dbConn.Open();
                int Count = dbCmd.ExecuteNonQuery();
                retVal = (Count > 0);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

    }
}
